// package main

// import (
// 	"flag"
// 	"fmt"
// 	"io/ioutil"
// 	"os"

// 	"github.com/russross/blackfriday/v2"
// )

// // go run main.go -input example.md -output example.html
// func main() {
// 	input := flag.String("input", "", "Input Markdown file")
// 	output := flag.String("output", "", "Output HTML file")
// 	flag.Parse()

// 	if *input == "" || *output == "" {
// 		fmt.Println("Usage: -input <markdown file> -output <html file>")
// 		return
// 	}

// 	data, err := ioutil.ReadFile(*input)
// 	if err != nil {
// 		fmt.Printf("Failed to read file: %v\n", err)
// 		return
// 	}

// 	html := blackfriday.Run(data)

// 	err = ioutil.WriteFile(*output, html, os.ModePerm)
// 	if err != nil {
// 		fmt.Printf("Failed to write file: %v\n", err)
// 		return
// 	}

// 	fmt.Println("Conversion completed successfully!")
// }

package main

import (
	"flag"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

func main() {
	// 命令行参数
	old := flag.String("oldstr", "", "旧内容")
	new := flag.String("newstr", "", "新内容")
	file := flag.String("file", "", "文件路径")

	flag.Parse()

	if *old == "" || *new == "" || *file == "" {
		fmt.Println("Usage: -old <old content> -new <new content> -file <file path>")
		return
	}

	// 读取文件内容
	data, err := ioutil.ReadFile(*file)
	if err != nil {
		fmt.Printf("Failed to read file: %v\n", err)
		return
	}

	// 替换内容
	content := string(data)
	content = strings.Replace(content, *old, *new, -1)

	// 写回文件
	err = ioutil.WriteFile(*file, []byte(content), os.ModePerm)
	if err != nil {
		fmt.Printf("Failed to write file: %v\n", err)
		return
	}

	fmt.Println("Content replaced successfully!")
}
